package com.ymxx.jweb.util;

import java.util.HashMap;
import java.util.Random;


public class StringUtil{

	private static final String range = "abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ1234567890";
	private StringUtil(){}
	/**
	 * to judge whether a string is empty,null or "" are regarded as empty
	 * @param str
	 * @return
	 */
	public static Boolean isBlank(String str){
		
		return str == null || "".equals(str.trim());
	}
	/**
	 * to judge if the given str contains illegal chars,if contails return false, if not contains,return true
	 * @param str 
	 * @param chars
	 * @return
	 */
	public static boolean isLegal(String str,char [] illegalChars){
		
		boolean flag = true;
		if(str == null){
			return !flag;
		}
		if(illegalChars == null || illegalChars.length == 0){
			return true;
		}
		char [] strChars = str.toCharArray();
		HashMap<Character,Integer> charMap = new HashMap<Character,Integer>(100);
		for(int i = 0 ; i < strChars.length ; i++){
			charMap.put(strChars[i], null);
		}
		for(int i = 0 ; i < illegalChars.length ; i++){
			if(charMap.containsKey(illegalChars[i])){
				return !flag;
			}
		}
		return flag;
	}
	/**
	 * @return
	 */
	public static String getRandomStr(){
		Random ran = new Random();
		StringBuffer results = new StringBuffer();
		for(int i = 0 ; i < 4 ; i++){
			results.append(range.charAt(ran.nextInt(range.length())));
		}
		return results.toString();
	}
	public static void main(String[] args) {
		System.out.println(getRandomStr());  
	}
}
